package com.paradox.aggregation.provider.juc;

import cn.hutool.core.date.DateUtil;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorTests {
    public static void main(String[] args)  throws InterruptedException {
        ExecutorService executorService=new ThreadPoolExecutor(2,5,1000, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(5));
        for(int i=0;i<10;i++){
            executorService.execute(() -> {
                try {
                    Thread.sleep(500);
                    System.out.println(Thread.currentThread().getId()+" is done");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
        System.out.println("xxx");
        System.out.println(DateUtil.format(new Date(),"yyyy-MM-ss HH:mm:ss"));
        executorService.shutdown();
        executorService.awaitTermination(100000,TimeUnit.MILLISECONDS);
        System.out.println(DateUtil.format(new Date(),"yyyy-MM-ss HH:mm:ss"));
    }
}
